<template>
  <div class="detailbox">
    <div class="flexbox">
      <div class="shrinkbox_v2">
        角色名称
      </div>
      <div class="contentbox_v2">
        <el-input v-if="!feildConfig.isReadonly" class="diyinput" v-model="editData.roleName" placeholder="请输入角色名称"></el-input>
        <div v-else class="div_input">
          {{ editData.roleName }}
        </div>
      </div>
    </div>
    <div class="flexbox">
      <div class="shrinkbox_v2">
        菜单列表
      </div>
      <div class="contentbox_v2">
        <div class="div_input">
            <el-tree
                v-if="menutree.length != 0"
                ref="menu_tree"
                :data="menutree"
                :props="{label: 'menuName', children: 'children'}"
                node-key="id"
                show-checkbox
                default-expand-all
                @check-change="handleCheckChange"
            />
        </div>
      </div>
    </div>

  </div>
</template>

<script setup>
  import { ref, inject, defineEmits, nextTick } from 'vue'
  // import { useStore } from 'vuex'
  // 注入全局utils工具js
  const $utils = inject('$utils')
  const editData = ref({})
  const feildConfig = ref({
    isReadonly: false
  })

  const menutree = ref([])

  const menu_tree = ref()
  // 子传父
  const emit = defineEmits([])

  async function initData(obj) {
    menutree.value = obj.menulist ? obj.menulist : []
    editData.value = obj.data.role ? obj.data.role : {}
    await nextTick()
    menu_tree.value.setCheckedKeys(obj.data.menus)
  }
  function submitData() {
    console.log('提交数据')
    console.log(editData.value)
    
    const menuids = menu_tree.value.getCheckedNodes()
    const ids = []
    for (var i = 0; i < menuids.length; i++) {
        ids.push(menuids[i].id)
    }
    $utils.post({
      url: '/Api/EntRole/DoSetSysMenu',
      params: {
        id: editData.value.id,
        data: ids
      },
      showLoading: true,
      ok: function (res) {
        $utils.message({
          message: res.msg,
          type: 'success'
        })
        emit('close-dialog', false)
      }
    })
  }

  defineExpose({
    initData,
    submitData
  })

</script>

<style scoped>
.saveBtn {
  background-color: #4999FA;
  color: #fff;
  font-weight: normal;
  font-size: 14px;
  padding: 3px 10px;
  border-radius: 3px;
  margin-right: 10px;
}
.saveBtn:hover {
  /* background-color: #7BB8FB; */
  opacity: 0.8;
  cursor: pointer;
}
.split_title {
  background-color: #EBEEF5;
  font-size: 16px;
  height: 30px;
  align-items: center;
  font-family: '楷体';
  font-weight: bold;
  display: flex;
  position: relative;
}
.split_title_content {
  flex-grow: 1;
  text-align: center;
}
.split_title_btn {
  display: flex;
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  align-items: center;
}
.shrinkbox_v2 {
  width: 70px;
}
.diyinput :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diyselect :deep(.el-select__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diyselect :deep(.el-select__wrapper:hover){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
.diyselect :deep(.el-select__wrapper:active){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
/* .diyselect :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
  pointer-events: none; 
}
.diyselect :deep(.el-input__wrapper:hover){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
.diyselect :deep(.el-input__wrapper:active){
  border: 0 !important;
  outline: none;
  box-shadow: none;
} */
.diyinput :deep(.el-textarea__inner){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diydatepicker :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diyformitem {
  margin-bottom: 0;
}
.diydatapicker :deep(.el-date-editor){
  width: 100%;
}
.diydatapicker :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
.diyinput :deep(.el-input-group__append){
  border: 0 !important;
  outline: none;
  background-color: unset;
  box-shadow: none;
  padding: 0 10px 0 5px;
  font-weight: bold;
  font-size: 16px;
}
/deep/ input::-webkit-outer-spin-button,
/deep/ input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
/deep/ input[type='number'] {
  -moz-appearance: textfield;
}
</style>